package com.example.hxds.mps.controller;

import com.example.hxds.common.util.R;
import com.example.hxds.mps.controller.form.CalculateDriverLineForm;
import com.example.hxds.mps.controller.form.EstimateOrderMileageAndMinuteForm;
import com.example.hxds.mps.service.MapService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;

@RestController
@RequestMapping("/map")
@Tag(name="MapController",description = "地图Web接口")
public class MapController {

    @Autowired
    private MapService mapService;

    @PostMapping("/estimateOrderMileageAndMinute")
    public R estimateOrderMileageAndMinute(@Valid @RequestBody EstimateOrderMileageAndMinuteForm form){

        HashMap map = mapService.estimateOrderMileageAndMinute(form.getMode(),
                form.getStartPlaceLatitude(), form.getStartPlaceLongitude(),
                form.getEndPlaceLatitude(), form.getEndPlaceLongitude());
        return R.ok().put("result",map);
    }

    @PostMapping("/calculateDriverLine")
    public R calculateDriverLine(@Valid @RequestBody CalculateDriverLineForm form){

        return R.ok().put("result",
                mapService.calculateDriverLine(  form.getStartPlaceLatitude(), form.getStartPlaceLongitude(),
                form.getEndPlaceLatitude(), form.getEndPlaceLongitude()));
    }
}
